
url=url+"admin/"
$(document).ready(function () {
})

getList()

function getList() {
    $.ajax({
        url:url+"getApplication.do",
        type:"get",
        datatype:"json",
        success:function (data) {
            data=JSON.parse(data)
            initTable(data)
        }
    })
    $('#AlertSuccess').addClass('hide');
}

function agree(t) {
    if($('input[name="roomid"]').val()!=null)
    {
        $.ajax({
            url:url+"dispartId.do",
            data:{username:application[t].username,roomid:$('input[name="roomid"]').val()},
            datatype:"json",
            type:"get",
            success:function (data) {
                if(data=="success")
                {
                    $.ajax({
                        url: url + "allow.do",
                        data: application[t],
                        datatype: "json",
                        type: "get",
                        success: function (data) {
                            if(data=="success")
                            {
                                $('tbody').find('tr[data='+t+']').remove();
                                $('#AlertSuccess').removeClass('hide');
                            }
                        }
                    })
                }
                else
                {
                    alert("房间号分配失败");
                }
            }
        })
    }
    else
    {
        alert("分配失败")
    }

}

function refuse(t) {
    $.ajax({
        url:url+"refuse.do",
        data:application[t],
        datatype:"json",
        type:"get",
        success:function (data) {
            if(data=="success")
            {
                $('tbody').find('tr[data='+t+']').remove();
            }
        }
    })
}

var application;
function initTable(data) {
    application=data;
    for(var i=0,j=data.length;i<j;i++)
    {
        $('tbody').append("<tr data='"+i+"'>" +
            "<td>"+data[i].username+"</td>" +
            "<td>"+data[i].realname+"</td>" +
            "<td>"+data[i].idcard+"</td>" +
            "<td>"+data[i].research+"</td>" +
            "<td>"+data[i].reason+"</td>" +
            "<td><input type='text' name='roomid' maxlength='8'></td>" +
            "<td><i class='fa fa-times fa-lg text-danger' title='不同意开通' onclick='refuse("+i+")'></i>" +
            "<i class='fa fa-check fa-lg text-success' title='同意开通直播' onclick='agree("+i+")'></i></td>" +
            "</tr>")
    }

}

$('.close').on('click',function () {
    $(this).parents('div').eq(0).addClass('hide');
})